package com.inviscidlabs.schooled;

import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.util.Log;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.widget.Toast;

public class ActivityClassEdit extends FragmentActivity{
	
private int editMode;
private long sId;

private final static int modeNewClass=799;
private final static int modeEditClass=798;
private final static int modeNewClassNoSemesters=777;

//variable of the extra given by schooled for determining what mode we are in
private int incomingEditMode;

private FragmentClassEdit fce;
	
	
//==========ON CREATE==========
	@Override
	public void onCreate(Bundle savedInstanceState){
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_classedit);
		incomingEditMode=getIntent().getExtras().getInt("editMode");
		sId=getIntent().getExtras().getLong("semId");
		fce=(FragmentClassEdit) getSupportFragmentManager().findFragmentById(R.id.fragment_classEdit);
		setEditMode(incomingEditMode);
		Log.i("incoming editMode value",String.valueOf(incomingEditMode));
		
		
	}
	
//========ON CREATE OPTIONS MENU=========
	@Override
	  public boolean onCreateOptionsMenu(Menu menu) {
		MenuInflater inflater = getMenuInflater();
		inflater.inflate(R.menu.actionbar_edit, menu);
		return true;
		
	}

//=============ON OPTIONS ITEM SELECTED===============
	@Override
	  public boolean onOptionsItemSelected(MenuItem item) {
		Log.i("optionsmenu triggered", String.valueOf(item.getItemId()));
		Log.i("editMode Int Value", String.valueOf(editMode));
	    switch (item.getItemId()) {
	    case R.id.menu_save:
	    	//save
	    	if(editMode==modeNewClassNoSemesters){
	    		fce.createClass(sId);
	    		finish();
	    		//TODO dialog to ask if they want to add another
	    	} else if(editMode==modeNewClass){
	    		fce.createClass(sId);
	    	} else if(editMode==modeEditClass){
	    		fce.editClass(0);
	    		//TODO, get some sort of id in there
	    	}
	    	return true;
	    }
	    
	    return false;
	    }

//=============SET EDIT MODE==============
	private void setEditMode(int initialIntent){		
		if(initialIntent==LeModule.EXTRA_ADDCLASSES_NOCLASSES){Log.i("newClassNoSem triggered", "OMG WE MADE IT");
		editMode=modeNewClassNoSemesters;
		Log.i("value of editMode", String.valueOf(editMode));}
	}

}
